//
//  UIView+NotData.m
//  JingCai
//
//  Created by xiaowuxiaowu on 16/5/23.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "UIView+NotData.h"

@implementation UIView (NotData)

- (UILabel *)messageLabel {
    UILabel *label = objc_getAssociatedObject(self, _cmd);
    if (!label) {
        label = [UILabel new];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = TPAllBackgroundColor;//[UIColor darkGrayColor];
//        label.font = [UIFont fontWithName:kTPMLingWaiMedium_SC size:24.0];
        label.numberOfLines = 0;
         [self addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.mas_centerX);
            make.top.mas_equalTo(self.pimageView.mas_bottom);
            make.width.mas_equalTo(self.mas_width).multipliedBy(0.9);
            make.height.mas_equalTo(HeightScaleSize(40.0));
        }];
       
        objc_setAssociatedObject(self, _cmd, label, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    return label;
}

- (UIImageView *)pimageView {
    UIImageView *imageView = objc_getAssociatedObject(self, _cmd);
    if (!imageView) {
        imageView = [[UIImageView alloc]initWithImage:ImageNamed(@"TP_No_Data")];
        
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_centerY).offset(-80.0);
            make.centerX.mas_equalTo(self.mas_centerX);
//            make.width.mas_equalTo(756/4);
            make.size.mas_equalTo(CGSizeMake(277/2, 248/2));
        }];
        
        objc_setAssociatedObject(self, _cmd, imageView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    return imageView;
}
-(void)tp_addNotMsg:(NSString *)message{
    
    self.pimageView.hidden = NO;
    self.messageLabel.hidden = NO;
    self.messageLabel.text = message;
   
    
    
}
-(void)tp_hideNotMsg{
    self.pimageView.hidden = YES;
    self.messageLabel.hidden = YES;
}




- (void)addHollowWithPath:(UIBezierPath *)path{
    
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        UIBezierPath *aPath = [UIBezierPath bezierPathWithRect:self.bounds];
        [aPath appendPath:[path bezierPathByReversingPath]];
        
        //创建出CAShapeLayer
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        
        //让贝塞尔曲线与CAShapeLayer产生联系
        shapeLayer.path = aPath.CGPath;
        
        //添加并显示
        [self.layer setMask:shapeLayer];
    });
}

- (void)addLineWithCGPath:(CGPathRef)path animation:(BOOL)isAnimation{
    
    [self addLineWithCGPath:path
               stockerColor:TPAllBackgroundColor
                  fillColor:[UIColor blackColor]
                    animation:isAnimation];
}

- (void)addLineWithCGPath:(CGPathRef)path
             stockerColor:(UIColor *)stokerColor
                fillColor:(UIColor *)fillColor animation:(BOOL)isAnimation

{
    CAShapeLayer *border = [CAShapeLayer layer];
    
    border.strokeColor = stokerColor.CGColor;
    
    border.fillColor = fillColor.CGColor;

    border.path = path;
    
    border.frame = self.bounds;
    
    border.lineWidth = 2.f;
    
    border.lineCap = @"square";
    
    border.lineDashPattern = @[@5, @5];
    
    [self.layer addSublayer:border];
    
    if(isAnimation){
        CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        pathAnimation.duration = 1.0;
        pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
        pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
        [border addAnimation:pathAnimation forKey:nil];
    }
   

}


@end
